#pragma once

#ifndef CONVEYORAGENT_H_
#define CONVEYORAGENT_H_

#include "Agent.h"
#include <list>
#include <QPoint>
#include <string>
#include "ScopedLock.h"
#include "Kit.h"
#include "KitRecipe.h"
#include "KitRobot.h"
#include "FactoryControlSystem.h"
#include "GUIConveyor.h"
#include "Sema.h"


#include "Conveyor.h"


class GUIConveyor;


//#pragma once
//
//#ifndef CONVEYORAGENT_H_
//#define CONVEYORAGENT_H_
//
//#include "Agent.h"
//#include <queue>
//#include <vector>
//#include <QPoint>
//#include <string>
//#include "Kit.h"
//#include "KitRobotAgent.h"
//#include "FactoryControlSystemAgent.h"
//#include "GUIConveyor.h"
//#include <list>
//#include "KitRecipe.h"
//
//class ConveyorAgent;
//class KitInterface;
//class FactoryControlSystemAgent;
//class GUIConveyor;
//class KitRobotAgent;
//class Kit;
//enum ConveyorAgentState;
//
class ConveyorAgent : public Agent, public Conveyor
{

private:
	ConveyorType myType;

	GUIConveyor* guiConveyor;
	FactoryControlSystem* FCS;
	KitRobot* kitRobot;
		
	Kit* currentKit;

	Sema kitSemaphore;
	Lock conveyorLock;
	//Actions

	//To Kit Robot
	 void handleKitEndConveyor();
	
	//To GUI
	 void tellGuiToProduceKit(KitRecipe* recipe);
	 void tellGuiToPickUpFinishedKit(KitInterface* kit);

public:
	
	ConveyorAgent(std::string, ConveyorType type); 
	~ConveyorAgent();
	
	std::list<KitRecipe*> kitRecipes;
	std::list<KitInterface*> finishedKits;

	//Messages
	
	//From FCS
	virtual void msgHereAreKits(KitRecipe* k);

	//From Kit Robot
	virtual void msgHereIsFinishedKit(KitInterface* k);
	virtual void msgKitPickedUp();
	virtual QPoint getPickUpKitPosition();
	virtual QPoint getDropOffKitPosition();

	// From GUI
	void msgKitEndOfConveyor(Kit* k);

	//Printable Interface
	virtual std::string toString() const;

	virtual bool pickAndExecuteAnAction();

	
	// Getters

	KitRobot* GetKitRobot(void)							{ return(kitRobot);		};

	std::list<KitRecipe*>& getKitRecipes();

	// Setters

	void setFCS (FactoryControlSystem*);
	void setGUI (GUIConveyor*);
	void setKitRobot(KitRobot* _kitRobot);


	//Non-norms
	void handleBreak();
	void handleFix();
};

#endif